package com.wushi.lenovo.asia5b.app_model.good

import com.mvp.base.model.BaseModel

/**
 * Created by zhangyuncai on 2020/6/23.
 */
class AddCartModel : BaseModel() {
    var popup_info: PopupInfo? = null
    var cart_detail: CartDetail? = null


    fun isDaigou(): Boolean {
        return cart_detail?.isDaigou()?:false
    }

    fun getSelectIds(): ArrayList<Int>? {
        return cart_detail?.cart_id
    }

    fun getTitle(): String? {
        return popup_info?.title
    }

    fun getContent(): String? {
        return popup_info?.message
    }

    fun getOk(): String? {
        return popup_info?.button?.continue_shopping
    }

    fun getCancel(): String? {
        return popup_info?.button?.goto_cart
    }

    /**
     * 是否具备dialog的因素
     */
    fun hasDialog(): Boolean {
        return !(getTitle().isNullOrEmpty() ||
                getContent().isNullOrEmpty() ||
                getOk().isNullOrEmpty() ||
                getCancel().isNullOrEmpty())
    }
}

class PopupInfo : BaseModel() {
    var title = ""
    var message = ""
    var button: PopupButton? = null
}

class PopupButton : BaseModel() {
    var continue_shopping = ""
    var goto_cart = ""
}

class CartDetail : BaseModel() {
    var cart_id: ArrayList<Int>? = null
    val type: String? = null // 1=daigou, 3=markeplace
    fun isDaigou(): Boolean {
        return type == "daigou"
    }
}
/*
{
    "result": 1,
    "data": {
        "cart_detail": {
            "cart_id": [
                154159,
                154160
            ],
            "member_cart": [
                {
                    "cart_id": 154159,
                    "quantity": 1,
                    "option": "cfcd208495d565ef66e7dff9f98764da:b4b147bc522828731
                    "remark": "",
                    "id": "447195"
                },
                {
                    "cart_id": 154160,
                    "quantity": 1,
                    "option": "cfcd208495d565ef66e7dff9f98764da:b4b147bc522828731
                    "remark": "",
                    "id": "447195"
                }
            ]
        },
        "popup_info": {
            "title": "已成功加入购物车",
            "message": "<div>1个新商品已添加到您的购物车。<\/div><div style=\"text-decoration:u
            "button": {
                "ok": "确认"
            }
        }
    },
    "msg": "Cart Item Successfully Added"
}
 */